package com.yt.controller;

import com.yt.entity.User;
import com.yt.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.websocket.server.PathParam;
import java.io.UnsupportedEncodingException;
import java.util.List;

/**
 * @Classname MyController
 * @Description
 * @Date 2021/11/6 8:44
 * @Create by 杨涛
 */
@RestController
public class MyController {


    @Value("${server.port}")
    private String port;
    @Autowired
    private UserMapper userMapper;

    @GetMapping("/setsession")
    public String setSession(HttpSession ses) {
        ses.setAttribute("user","laoyang");
        return "ok";
    }
    @GetMapping("/getsession")
    public String getSession(HttpSession ses) {
        return ses.getAttribute("user").toString();
    }


    @GetMapping("/json/users")

    public List<User> getUsers() throws UnsupportedEncodingException {

        return   userMapper.getUsers();
    }

    @GetMapping("/user/{id}.html")
    public User getUserByid(@PathVariable int id){
        return   userMapper.getUserById(id) ;
    }

    @RequestMapping(value = "/getinfo")//,method = RequestMethod.POST)
    public String getinfo(
//    @PathParam("password") int password,
//    @RequestParam(value = "username" ,required = false)String username
    //                      String username,int password
      User user )
    {
        return user.getUsername()+ "--"+user.getPassword();
    }
}
